<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>
			人元添加
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="css/main.css" media="all">
		<link rel="stylesheet" href="css/bootstrap.css">
		<script type="text/javascript" src="lib/loading/okLoading.js"></script>
		<script src="js/base.js"></script>
		<style>
			.imgs {
				display: none;
			}
		</style>

	</head>
	<body>

		<div class="x-body">
			<form class="layui-form layui-form-pane" action="" id="add">
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<input type="hidden" name="id" value="">
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>所属小区
								</label>
								<div class="layui-input-block">
									<select name="community_id" id="community_id">
										<script>
											let cheweiString = localStorage.getItem("chewei_edit");
											let chewei = JSON.parse(cheweiString);
											let url = "http://localhost:8080/wuye/XiaoQuController/selectXiaoQuAll";
											rest(url, "get", null, function(r) {
												let arr = r.data;
												let innerHTML = "";

												for (let i = 0; i < arr.length; i++) {
													if (chewei.suoshuxiaoqu == arr[i].mingcheng) {
														innerHTML = innerHTML + " <option value=\"" + arr[i].mingcheng + "\" selected>" + arr[i]
															.mingcheng +
															"</option>";
													} else {
														innerHTML = innerHTML + " <option value=\"" + arr[i].mingcheng + "\" >" + arr[i]
															.mingcheng +
															"</option>";
													}

												}
												document.getElementById("community_id").innerHTML = innerHTML;
											});
										</script>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>车位名称
								</label>
								<div class="layui-input-block">
									<input type="text" id="parkName" name="park_name" autocomplete="off"
										placeholder="空制在80个汉字，160个字符以内" class="layui-input" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">
									<span class='x-red'>*</span>状态
								</label>
								<div class="layui-input-block">
									<input type="radio" name="status" value="1" title="使用中">
									<div class="layui-unselect layui-form-radio layui-form-radioed"><i
											class="layui-anim layui-icon layui-anim-scaleSpring"></i>
										<div>使用中</div>
									</div>
									<input type="radio" name="status" value="0" title="闲置中" checked="checked">
									<div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
										<div>闲置中</div>
									</div>
								</div>
							</div>


							<div class="layui-form-item">
								<button class="layui-btn" type="button" lay-filter="add" lay-submit="">
									保存
								</button>
							</div>
							<!--</form>-->
							<div style="height:100px;"></div>
						</div>



					</div>

				</div>
			</form>
		</div>
		<script src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/x-layui.js" charset="utf-8"></script>
		<!-- 		<script type="text/javascript">
			//实例化编辑器
			//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
			UE.getEditor('cXiaoQuControllerontent', {
				initialFrameWidth: 1000,
				initialFrameHeight: 400,
			});
		</script> -->
		<script>
			document.getElementById("community_id").value = chewei.suoshuxiaoqu;
			document.getElementById("parkName").value = chewei.cheweimingcheng;
			let states = document.getElementsByName("status");
			if (chewei.zhuangtai == 0) {
				states[0].checked = "checked";
			} else {
				states[1].checked = "checked";
			}


			layui.use(['element', 'layer', 'form'], function() {
				$ = layui.jquery; //jquery
				lement = layui.element(); //面包导航
				layer = layui.layer; //弹出层
				form = layui.form()
				okLoading.close($);




				//监听提交
				form.on('submit(add)', function(data) {
					let suoshuxiaoqu = document.getElementById("community_id").value;
					let cheweimingcheng = document.getElementById("parkName").value;
					let states = document.getElementsByName("status");
					let state = 0;
					if (states[0].checked) {
						state = 0;
					} else {
						state = 1;
					}
					let url = "http://localhost:8080/wuye/CheWeiController/edit";
					let method = "post";
					let json = {};
					json.id = chewei.id;
					json.suoshuxiaoqu = suoshuxiaoqu;
					json.cheweimingcheng = cheweimingcheng;
					json.state = state;
					rest(url, method, json, function(r) {
						if (r.code == 200) {
							//添加成功
							layer.msg("修改成功", {
								icon: 6,
								time: 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.msg("修改失败", {
								icon: 5,
								time: 2000
							});
							return false;
						}
					});
					return false;
				});

			})
		</script>


	</body>
</html>